package smsapi.util;

import java.security.MessageDigest;

public class Md5Util {

    public static String md5(String dataStr,String charsetName) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(dataStr.getBytes(charsetName));
            byte digest[] = m.digest();
            StringBuilder sb = new StringBuilder();
            for(int i=0;i<digest.length;i++) {
                sb.append(String.format("%02x", digest[i]));
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
